package fr.esiag.isidis.pdsTeam.views;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;

import fr.esiag.isidis.pdsTeam.beans.Ligne;
import fr.esiag.isidis.pdsTeam.beans.Station;

public class LigneView extends JPanel {
	int x,y;
	Ligne L;
	int distance;
	
	public LigneView(Ligne L,int x,int y,int distance){
		this.distance=distance;
		this.x=x;
		this.y=y;
		this.L=L;
		//Graphics2D graphics2d =(Graphics2D)this.getGraphics();
		repaint();
	}
	@Override
	public void paint(Graphics g) {
		// TODO Auto-generated method stub
		super.paint(g);
		Graphics2D graphics2d =(Graphics2D)g;
		int i=-1;
		Font font= new Font("Helvetica", Font.BOLD, 14);
		graphics2d.setFont(font);
		for( Station station : L){
			if(i==-1)
			{
				StationView stationView=new StationView(x-17, y+20,station);
				graphics2d.drawImage(ResourceImage.getInstance().getStation(), stationView.getX(), stationView.getY(), null);
				String[] stationNames=station.getLibelle().split(" ");
				 for(int j=0;j<stationNames.length;j++)
				 { 
					 graphics2d.drawString(stationNames[j], stationView.getX()+(stationNames[j].length()*2)*(-2)+10,stationView.getY()+65+(j*15));
				 }
				i++;
				continue;
			}
			for(int j=0;j<3;j++)
			{
				graphics2d.drawImage(ResourceImage.getInstance().getRail(), x+(i*distance)+(j*85),y, null);
				graphics2d.drawImage(ResourceImage.getInstance().getRail(), x+(i*distance)+(j*85),y+55, null);
			}
			StationView stationView=new StationView(x-17+((i+1)*distance), y+20,station);
			graphics2d.drawImage(ResourceImage.getInstance().getStation(),stationView.getX() , stationView.getY(), null);
			 String[] stationNames=station.getLibelle().split(" ");
			 for(int j=0;j<stationNames.length;j++)
			 {
				 
				 graphics2d.drawString(stationNames[j], stationView.getX()+(stationNames[j].length()*2)*(-2)+10,stationView.getY()+65+(j*15));
			 }
			i++;
		}
	}
	public int getDistance() {
		return distance;
	}
	public void setDistance(int distance) {
		this.distance = distance;
	}
	public Image getImage() {
		BufferedImage image = new BufferedImage(1200,500,BufferedImage.BITMASK);
		Graphics2D g2d = image.createGraphics();
		paint(g2d);
		return image;
	}
	public int getPosX() {
		return x;
	}
	public int getPosY() {
		return y;
	}
	
}
